-
Notifications
You must be signed in to change notification settings - Fork 14k
Replace Rvalue::NullaryOp by a variant in mir::Operand. #148766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Some changes occurred to the CTFE machinery Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt
cc @rust-lang/wg-const-eval Some changes occurred in cc @BoxyUwU Some changes occurred in src/tools/clippy cc @rust-lang/clippy This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras Some changes occurred to the CTFE / Miri interpreter cc @rust-lang/miri This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a Some changes occurred in match checking cc @Nadrieril Some changes occurred to constck cc @fee1-dead This PR changes a file inside |
This comment has been minimized.
This comment has been minimized.
9560745 to
741855c
Compare
This comment has been minimized.
This comment has been minimized.
741855c to
dcf0916
Compare
| /// Special constants whose value depends on the evaluation context. Their value depends on a | ||
| /// flag on the crate being codegenned. | ||
| RuntimeChecks(RuntimeChecks), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For const-eval execution, their value is fixed, right?
|
It seems slightly odd to call these things "constants" when they have a different value inside and outside of const blocks... I am not sure whether this actually breaks anything today, but it seems at least conceptually suboptimal and could lead to issues down the line. For instance, if a constant's body entirely consists just of one of these new constants, then replacing that outer constant by the inner one is not correct (or at least, it can change program behavior) -- so e.g. @saethlin's "trivial const" machinery might need a special case for this. |
|
☔ The latest upstream changes (presumably #148658) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I agree that's not entirely satisfactory. Another design would put the variant inside |
|
That would be marginally better ("values" really should be unchanging), though still a footgun e.g. with the trivial const machinery I mentioned. Making them a new variant of |
dcf0916 to
76bdfae
Compare
This comment has been minimized.
This comment has been minimized.
76bdfae to
68c2a27
Compare
This comment has been minimized.
This comment has been minimized.
Latest commit does that. Cleaner than I expected. |
This comment has been minimized.
This comment has been minimized.
68c2a27 to
4183df4
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
| // We can't look at `tcx.sess` here as that can differ across crates, which can lead to | ||
| // unsound differences in evaluating the same constant at different instantiation sites. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't really make sense in the dummy machine.
| Constant(ref a) => write!(fmt, "{a:?}"), | ||
| Copy(ref place) => write!(fmt, "copy {place:?}"), | ||
| Move(ref place) => write!(fmt, "move {place:?}"), | ||
| RuntimeChecks(checks) => write!(fmt, "const {checks:?}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"const" is an odd choice, given that we moved it out of the constants
| /// Special constants whose value depends on the evaluation context. Their value depends on a | ||
| /// flag on the crate being codegenned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Special constants whose value depends on the evaluation context. Their value depends on a | |
| /// flag on the crate being codegenned. | |
| /// Query the compilation session of the current crate for a particular flag. | |
| /// This is not quite a const since its value can differ across crates within a single crate graph. |
| local_decls.local_decls()[l.local].source_info.span | ||
| } | ||
| Operand::Constant(c) => c.span, | ||
| Operand::RuntimeChecks(_) => DUMMY_SP, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is fine since user code won't contain this operand?
Based on #148151
This PR fully removes the MIR
Rvalue::NullaryOp. After #148151, it was only useful for runtime checks likeub_checks,contract_checksandoverflow_checks.These are "runtime" checks, boolean constants that may only be
truein codegen. It depends on a rustc flag passed to codegen, so we need to represent those flags cross-crate.This PR replaces those runtime checks by special variants in MIR
ConstValue. This allows code that expects constants to manipulate those as such, even if we may not always be able to evaluate them to actual scalars.